# chat with computer demo
import os

import agentscope
from agentscope.agents import UserAgent
from agentscope.service import (
    ServiceToolkit,
)
from agentscope.service import execute_python_code, execute_shell_command

from agentscope.agents.react_agent import ReActAgent

model_configs = [
    {
        "model_type": "openai_chat",
        "config_name": "qwen2.5-7b-local",
        # "model_name": "qwen2.5:7b-instruct-fp16",
        "model_name": "qwen2.5:7b-instruct-q4_0",
        "client_args": {
            "base_url": "http://127.0.0.1:11434/v1",
        },
        "api_key": "Empty",
        "generate_args": {"temperature": 0.2},
        "stream": True,
    },
    {
        "model_type": "openai_chat",
        "config_name": "qwen2.5-7b",
        "model_name": "Qwen/Qwen2.5-7B-Instruct",
        "client_args": {
            "base_url": "https://api-inference.modelscope.cn/v1",
        },
        "api_key": os.environ.get("MODELSCOPE_ACCESS_TOKEN"),
        "generate_args": {"temperature": 0.2},
        "stream": True,
    },
    {
        "model_type": "openai_chat",
        "config_name": "deepseek-r1:7b",
        "model_name": "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B",
        "client_args": {
            "base_url": "https://api.siliconflow.cn/v1",
        },
        "api_key": os.environ.get("SILICON_API_KEY"),
        "generate_args": {"temperature": 0.6},
        "stream": True,
    }
]
agentscope.init(model_configs=model_configs, studio_url="http://127.0.0.1:5000/")
# agentscope.init(model_configs=model_configs)


# Prepare the tools for the agent
service_toolkit = ServiceToolkit()

service_toolkit.add(execute_python_code)
service_toolkit.add(execute_shell_command)

# Create agents
agent = ReActAgent(
    name="assistant",
    model_config_name="qwen2.5-7b-local",
    verbose=True,
    service_toolkit=service_toolkit,
    max_iters=3,
    sys_prompt="你是一个擅长使用命令行工具以及代码生成的电脑助手，你操作的电脑是Windows11,你可以通过命令查询，如wmic命令查询系统信息来回答用户问题，以及通过python代码生成和调用代码执行工具来回答复杂问题的能力！"
)
user = UserAgent(name="User", input_hint="User Input ('exit' to quit): ")

# Build
x = None
while True:
    x = user(x)
    if x.content == "exit":
        break
    x = agent(x)
